<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

</body>
<script>
var url = "https://www.baidu.com/product/list?id=12345&sort=discount#title"
function parseUrl(url) {
  var a = document.createElement('a');
  a.href = url;
  console.log( a );
  console.log(a.protocol.replace(':', ''));
  console.log( a.hostname );
  console.log( a.search );
  console.log( a.search.replace(/^\?/, '').split('&') );
  return {
    protocol: a.protocol.replace(':', ''),
    host: a.hostname,
    params: (() => {
      var ret = {}, querys = [];
      var searchQuery = a.search.replace(/^\?/, '').split('&');
      for (var i = 0; i < searchQuery.length; i++) {
        if (searchQuery[i]) {
          querys = searchQuery[i].split('=');
          ret[querys[0]] = querys[1];
        }
      }
      return ret;
    })(),
    hash: a.hash.replace('#', '')
  };
}
var obj = parseUrl(url)
console.log(obj);
</script>
</html>